<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改宿舍住宿记录')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-dormitoryRecord-edit" th:object="${dormitoryRecord}">
            <input name="recordNumber" th:field="*{recordNumber}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">宿舍编号：</label>
                <div class="col-sm-8">
                    <input name="dormitoryNumber" th:field="*{dormitoryNumber}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">员工编号：</label>
                <div class="col-sm-8">
                    <input name="employeeNumber" th:field="*{employeeNumber}" class="form-control" type="text" onblur="getNameDepartment()">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">员工姓名：</label>
                <div class="col-sm-8">
                    <input name="employeeName" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">员工部门：</label>
                <div class="col-sm-8">
                    <input name="department" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">手机号码：</label>
                <div class="col-sm-8">
                    <input name="phoneNumber" th:field="*{phoneNumber}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">床位类型：</label>
                <div class="col-sm-8">
                    <select name="bedType" class="form-control " th:with="type=${@dict.getType('bed_type')}"
                            required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">入住时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="checkInTime" th:value="${#dates.format(dormitoryRecord.checkInTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label ">退宿时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="checkOutTime" th:value="${#dates.format(dormitoryRecord.checkOutTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "dormitory/dormitoryRecord";
        $("#form-dormitoryRecord-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-dormitoryRecord-edit').serialize());
            }
        }

        function getNameDepartment(){
            var employeeNumber = $("input[name='employeeNumber']").val();
            $.get("http://172.20.203.11/getoanamedept",{nameid: employeeNumber},function (response){
                var parse = JSON.parse(response);
                if (parse.code == "1") {
                    $("input[name='employeeName']").val(parse.name)
                    $("input[name='department']").val(parse.parent)
                }
                if (parse.code != "1") {
                    $("input[name='employeeName']").val("");
                    $("input[name='department']").val("");
                }
            });
        };

        $("input[name='checkInTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='checkOutTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>